import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import svgLoader from 'vite-svg-loader'
import path from 'path';
import { visualizer } from 'rollup-plugin-visualizer';
import { minifyHtml, injectHtml } from 'vite-plugin-html';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: [
      { find: "@", replacement: path.resolve(__dirname, 'src') }
    ],
  },
  build: {
    outDir: 'dist',
    //     lib:{
    //   entry: path.resolve(__dirname, 'src/App.tsx'),
    // name:'MyScreen',fileName:'MyScreen',formats:['es']},
    commonjsOptions: {
      include: /node_modules/,
      // 需要编译的组件
      dynamicRequireTargets: ['node_modules/***插件***/*.js']
    },
    minify: true,
    rollupOptions: {
      plugins: [
        visualizer(
          {
            filename: path.resolve(__dirname, 'dist/stats.html'),
            template: 'treemap',
            sourcemap: false
          }
        )
      ],
      output: {
        namespaceToStringTag: true // close this option, so that router dynamic import will result "Cannot read property 'toStringTag' of undefined". reference: https://github.com/vitejs/vite/issues/1921
      }
    },
    sourcemap: true
  },
  base:'./',
  server: {
    proxy: {
      '/api/': {
        target: 'https://localhost:3000/',
        changeOrigin: true
      }
    }
  }
})
